<?php

namespace app\api\controller;

use think\Db;

class Proxy extends Common
{
    public function info()
    {
        $data = Db::name('proxy_auth')->field('nickname, idcard, phone, name, count, image, status, reason')->where(['user_id' => $this->member['id']])->find();
        
        if ($data) {
            $data['image'] = changeUrl($data['image']);
        } else {
            $data = (object)[];
        }
        
        return $this->pass($data);
    }
    
    
    public function join()
    {
        if ($this->member['proxy']) return $this->miss('已是代理身份，无需重新申请');
        
        $result = Db::name('proxy_auth')->where(['user_id' => $this->member['id'], 'status' => 0])->find();
        if ($result) return $this->miss('申请中，请等待审核结果');
    
        $this->params['create_time'] = $this->params['update_time'] = time();
    
        $data = Db::name('proxy_auth')->where(['user_id' => $this->member['id']])->find();
        
        if ($data) {
            Db::name('proxy_auth')->delete($data['id']);
        }
    
        Db::name('proxy_auth')->insert($this->params);
        
        return $this->pass('申请提交成功，请等待审核结果');
    }
}




